package com.lpwa.system.service.impl;

import java.util.List;

import com.lpwa.common.utils.StringUtils;
import com.lpwa.system.domain.AlarmQuickText;
import com.lpwa.system.domain.AlarmRuleConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lpwa.system.mapper.TagAlarmDataMapper;
import com.lpwa.system.domain.TagAlarmData;
import com.lpwa.system.service.ITagAlarmDataService;
import com.lpwa.common.core.text.Convert;

/**
 * 标签报警历史 服务层实现
 * 
 * @author tanmu
 * @date 2019-06-22
 */
@Service
public class TagAlarmDataServiceImpl implements ITagAlarmDataService 
{
	@Autowired
	private TagAlarmDataMapper tagAlarmDataMapper;
	/**
     * 查询标签报警历史信息
     * 
     * @param id 标签报警历史ID
     * @return 标签报警历史信息
     */
    @Override
	public TagAlarmData selectTagAlarmDataById(Long id)
	{
	    return tagAlarmDataMapper.selectTagAlarmDataById(id);
	}
	
	/**
     * 查询标签报警历史列表
     * 
     * @param tagAlarmData 标签报警历史信息
     * @return 标签报警历史集合
     */
	@Override
	public List<TagAlarmData> selectTagAlarmDataList(TagAlarmData tagAlarmData)
	{
	    return tagAlarmDataMapper.selectTagAlarmDataList(tagAlarmData);
	}
	
    /**
     * 新增标签报警历史
     * 
     * @param tagAlarmData 标签报警历史信息
     * @return 结果
     */
	@Override
	public int insertTagAlarmData(TagAlarmData tagAlarmData)
	{
	    return tagAlarmDataMapper.insertTagAlarmData(tagAlarmData);
	}
	
	/**
     * 修改标签报警历史
     * 
     * @param tagAlarmData 标签报警历史信息
     * @return 结果
     */
	@Override
	public int updateTagAlarmData(TagAlarmData tagAlarmData)
	{
	    return tagAlarmDataMapper.updateTagAlarmData(tagAlarmData);
	}

	/**
     * 删除标签报警历史对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteTagAlarmDataByIds(String ids)
	{
		return tagAlarmDataMapper.deleteTagAlarmDataByIds(Convert.toStrArray(ids));
	}
	/**
	 * 查询报警规则配置信息
	 *
	 * @param id 报警规则配置ID
	 * @return 报警规则配置信息
	 */
	@Override
	public AlarmRuleConfig selectAlarmRuleConfigById(Long id)
	{
		return tagAlarmDataMapper.selectAlarmRuleConfigById(id);
	}
	/**
	 * 修改报警规则配置
	 *
	 * @param alarmRuleConfig 报警规则配置信息
	 * @return 结果
	 */
	@Override
	public int updateAlarmRuleConfig(AlarmRuleConfig alarmRuleConfig)
	{
		return tagAlarmDataMapper.updateAlarmRuleConfig(alarmRuleConfig);
	}

	@Override
	public int saveQuickText(List<String> list,String loginName) {
		//先删除表中记录
		tagAlarmDataMapper.deleteAlarmQuickTextByCreateBy(loginName);
		//插入
		if (StringUtils.isNotEmpty(list)){
			for (String str:list){
				AlarmQuickText alarmQuickText = new AlarmQuickText();
				alarmQuickText.setQuickText(str);
				alarmQuickText.setCreateBy(loginName);
				tagAlarmDataMapper.insertAlarmQuickText(alarmQuickText);
			}
		}
		return 1;
	}
}
